<?php
if (isset($_GET['notification']) && !empty($_GET['notification']))
{
	switch($_GET['notification'])
	{
		case "uplosuccess":
			?>
			<div class="success notification">
				Die Datei "<?php echo $_GET['uplo_filename']; ?>" wurde erfolgreich hochgeladen!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>	
			<?php
			break;
		case "uplofail":
			?>
			<div class="error notification">
				<?php echo LANG_ACTION_UPLOAD_FAIL; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
			<?php
			break;
	}
}
else if (isset($_POST['newfilecontent']) && isset($_POST['filetosave']))
{
	$file = "../tmp/" . array_pop(explode("/", $_POST['filetosave']));
	$editedfile = array_pop(explode("/", $_POST['filetosave']));
	$openfile = fopen($file, "w");
	fwrite($openfile, stripslashes($_POST['newfilecontent']));
	fclose($openfile);
	$ftp->delete($_POST['filetosave']);
	$ftp->upload($file, $_POST['filetosave']);
	if(unlink($file))
	{
	?>
		<div class="success notification">
			Die Datei "<?php echo $editedfile; ?>" wurde erfolgreich gespeichert!
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
	else
	{
	?>
		<div class="error notification">
			Fehler beim speichern der Datei "<?php echo $editedfile; ?>"!
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
}
else if (isset($_GET['newdir']))
{
	if(!empty($_GET['newdir']))
	{
		if($ftp->makeDir( $_GET['newdir'], 1 ))
		{
		?>
			<div class="success notification">
				Der Ordner "<?php echo $_GET['newdir']; ?>" wurde erfolgreich angelegt!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_NEWDIR_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
	}
	else
	{
	?>
		<div class="error notification">
			<?php echo LANG_ACTION_NEWDIR_FAIL_NO_NAME; ?>
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
}

else if (isset($_GET['newfile']))
{
	if(!empty($_GET['newfile']))
	{
		$onlyfile = array_pop(explode("/", $_GET['newfile']));
		$tempfilename = "../tmp/" . $onlyfile;
		
		$tempfile = fopen($tempfilename, "w");
		fclose($tempfile);
	
		if ($ftp->upload($tempfilename, $onlyfile) && unlink($tempfilename))
		{
		?>
			<div class="success notification">
				Die Datei "<?php echo $onlyfile; ?>" wurde erfolgreich angelegt!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_NEWFILE_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
	}
	else
	{
	?>
		<div class="error notification">
			<?php echo LANG_ACTION_NEWFILE_FAIL_NO_NAME; ?>
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
}
	
else if (isset($_GET['rename']) && isset($_GET['oldname']) && isset($_GET['type']))
{
	if(@$ftp->rename( $_GET['oldname'], $_GET['rename'] ))
	{
		if($_GET['type'] == "dir")
		{
		?>
			<div class="success notification">
				Der Ordner "<?php echo $_GET['oldname']; ?>" wurde erfolgreich in "<?php echo $_GET['rename'];  ?>" umbenannt!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="success notification">
				Die Datei "<?php echo $_GET['oldname']; ?>" wurde erfolgreich in "<?php echo $_GET['rename']; ?>" umbenannt!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
	}
	else
	{
		if($_GET['type'] == "dir")
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_RENAME_DIR_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_RENAME_FILE_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
	}
}

else if (isset($_GET['delete']))
{
	if ($_GET['type'] == "dir")
	{
		if(@$ftp->removeDir( $_GET['delete'], 1 ))
		{
		?>
			<div class="success notification">
				Der Ordner "<?php echo $_GET['delete']; ?>" wurde erfolgreich gelöscht!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_DELETE_FILE_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}	
	}
	else
	{
		if(@$ftp->delete( $_GET['delete'] ))
		{
		?>
			<div class="success notification">
				Die Datei "<?php echo $_GET['delete']; ?>" wurde erfolgreich gelöscht!
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
		else
		{
		?>
			<div class="error notification">
				<?php echo LANG_ACTION_DELETE_FILE_FAIL_NO_AUTHORIZATION; ?>
				<span class="closeNotification" onclick="closeNotification()">
					X
				</span>
			</div>
		<?php
		}
	}
}

else if (isset($_GET['chmod']) && isset($_GET['tochmod']))
{
	$chmod = octdec(str_pad($_GET['chmod'],4,'0',STR_PAD_LEFT)); 
	if($ftp->chmod($_GET['tochmod'], $chmod))
	{
	?>
		<div class="success notification">
			Die Berechtigung von "<?php echo $_GET['tochmod']; ?>" wurde erfolgreich geändert!
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
	else
	{
	?>
		<div class="error notification">
			<?php echo LANG_ACTION_CHMOD_FAIL_NO_AUTHORIZATION; ?>
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
}

else if (isset($_GET['language']))
{
	if ($_GET['language'] == "edit")
	{
	?>
		<div class="success notification">
			<?php echo LANG_ACTION_SETTINGS_SAVE_SUCCESS; ?>
			<span class="closeNotification" onclick="closeNotification()">
				X
			</span>
		</div>
	<?php
	}
	else
	{
		$language = $_GET["language"];
		setcookie("language", $language, time()+(3600*24*365));
		?>
		<script>
			ajaxfade('ajax/showdirectory.php?language=edit', '#slider');
		</script>
	<?php
	}
}
?>